package com.example.ycq.service.impl;

import com.example.ycq.pojo.User;
import com.example.ycq.service.MyBatisUserService;
import com.example.ycq.service.UserBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserBatchServiceImpl implements UserBatchService {

    @Autowired
    private MyBatisUserService myBatisUserService=null;

    @Override
    //propagation:传播, Propagation.REQUIRED：如果当前由事务就用当前事务，否则新建
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED )
    public int insertUsers(List<User> userList) {
        int count=0;
        for(User user:userList){
            //调用子方法，将使用@Transactional定义的传播行为
            count+=myBatisUserService.insertUser(user);
        }
        return count;
    }





}
